package logic

import (
	"context"
	"user_srv/model/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoByMobileLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserInfoByMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoByMobileLogic {
	return &GetUserInfoByMobileLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 根据手机号获取信息
func (l *GetUserInfoByMobileLogic) GetUserInfoByMobile(in *user.GetUserInfoByMobileReq) (*user.GetUserInfoByMobileResp, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	mobile := u.ByUserMobile(in.Mobile)
	return &user.GetUserInfoByMobileResp{
		UserId:   int64(u.ID),
		Username: mobile.Username,
		Password: mobile.Password,
		Mobile:   mobile.Mobile,
		Salt:     mobile.Salt,
	}, nil
}
